function randomNumber(n){
    var rnd="";
    for(var i=0;i<n;i++)
        rnd+=Math.floor(Math.random()*10);
    return rnd;
}

function randomRangeNumber(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

function randomString(len) { 
	  len = len || 32; 
	  var chars = 'abcdefghijklmnopqrstuvwxyz'; 
	  var maxPos = chars.length; 
	  var pwd = ''; 
	  for (i = 0; i < len; i++) { 
	    pwd += chars.charAt(Math.floor(Math.random() * maxPos)); 
	  } 
	  return pwd; 
	} 

function randomStringNumber(l){
	  var s= '';
	  var randomchar=function(){
	   var n= Math.floor(Math.random()*62);
	   if(n<10) return n; //1-10
	   if(n<36) return String.fromCharCode(n+55); //A-Z
	   return String.fromCharCode(n+61); //a-z
	  }
	  while(s.length< l) s+= randomchar();
	  return s;
}

function to_sort(sortMode,sortName)
{	   	
	var sortUrl=winUrl(location.href,sortMode,sortName);
	window.location.href=sortUrl;
}

function to_page(pageIndex,pageSize)
{	   	
	var pageUrl=winUrl(window.location.href,"pageIndex",pageIndex);
	window.location.href=winUrl(pageUrl,"pageSize",pageSize);
}


//删除左右两端的空格
function to_trim(str){   
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 


//替换url的参数
function replaceParam(param,value,url){
	if(!url){
		url = window.location.href;
	}
	var pathIndex = url.indexOf(param);
	//如果url中没有次参数，添加
	if(pathIndex<0){
		url = url + "&" + param + "=" + value;
	}else{
		var urlBef = url.substring(0,pathIndex);
		var aft = url.substring(pathIndex,url.length);
		var urlAft;
		if(aft.indexOf("&")>0){
			 urlAft = aft.substring(aft.indexOf("&"));
		}else{
			urlAft = "";
		}
		url = urlBef + param + "=" + value + urlAft;
	}
	return url
}

function winUrl(urlStr,qs,parm)
{	
	var url=urlStr;
	if(urlStr.indexOf("?")<0)
	{
		url= urlStr+"?"+qs+"="+parm;		
	}
	else if(urlStr.indexOf(qs+"=")<0){
		url= urlStr+"&"+qs+"="+parm;
	}	
	else{
		var s = urlStr.replace("?","?&").split("&");
		var re = "";
		for(i=1;i<s.length;i++){
		    if(s[i].indexOf(qs+"=")==0){
		        url= urlStr.replace(s[i],qs+"="+parm);
		    }
		}	
	}
	return url;
}














